﻿using System;
using System.Collections.Generic;
using System.Linq;
using SuppKids.Resources;

namespace SuppKids.Core.Extensions
{
    public static class EnumExtensions
    {
        private static readonly IEnumerable<DayOfWeek> daysOfWeeks = new[] {DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday };
        private const string enumTemplate = "{0}_{1}";

        public static string GetLocalizedEnumValue(this object value)
        {
            string result = null;

            if (value != null)
            {
                var enumType = value.GetType();

                if (!(value is Enum))
                {
                    return value.ToString();
                }

                result = Enums.ResourceManager.GetString(string.Format(enumTemplate, enumType.Name, Enum.GetName(enumType, value))) ?? value.ToString();
            }

            return result;
        }
        public static IEnumerable<T> GetPossibleValues<T>()
        {
            if (typeof (T) == typeof (DayOfWeek))
            {
                return daysOfWeeks.Cast<T>();
            }

            return Enum.GetValues(typeof(T)).Cast<T>();
        }
    }
}